import backtrader as bt
from target.indicator_ma import *


#用户代码init
def init(self):
    self.dataclose = self.datas[0].close
    
    self.me1 = ema(self.datas[0].close,12)
    self.me2 = ema(self.datas[0].close,26)

    # self.macd = self.me1 - self.me2
    # self.signal = ema(self.macd,9)

#用户策略代码
def on_bar(self):
    pass
    # if self.order:
    #     return
    # self.cash = self.get_cash()   #获取现金
    # self.dates = self.datas[0].datetime.date(0).isoformat()  #当前日期

    
    # #没有持仓
    # if not self.position:

    #     condition1 = self.macd[-1] - self.signal[-1]
    #     condition2 = self.macd[0] - self.signal[0]

    #     if condition1 < 0 and condition2 > 0:
    #         self.buy()
    # # 有持仓
    # else:

    #     condition = (self.dataclose[0] - self.bar_executed_close) / self.dataclose[0]

    #     if condition > 0.1 or condition < -0.1:
    #         self.sell()